//
//  PSPerfilViewController.m
//  psique
//
//  Created by Saulo Prado on 25/07/13.
//  Copyright (c) 2013 Saulo Prado. All rights reserved.
//

#import "PSPerfilViewController.h"
#import "PSCustomCell.h"


@interface PSPerfilViewController ()


@end

@implementation PSPerfilViewController
@synthesize slider;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 5000)];
    
    NSString *strURL = [NSString stringWithFormat:@"http://192.168.254.233:8080/psperfil.php?codigo=%d", 1];
    
    // execute php code
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
    
    strResult = [[NSMutableString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
    
     NSString *num = [strResult substringWithRange:NSMakeRange(0,1)];
    
    nrLinhas = [num intValue];
  
    NSString *subStrings = [strResult substringWithRange:NSMakeRange(2,strResult.length -3)];
    
  // NSString *tripa = [NSString stringWithFormat:@"%@", strResult];
    
     array = [subStrings componentsSeparatedByString:@";"];
    
    NSLog(strResult);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return nrLinhas;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    PSCustomCell * cell;
    
    static NSString *cellID=@"PSCustomCell";
    
    cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil)
    {
        NSArray *test = [[NSBundle mainBundle ]loadNibNamed:@"PSCustomCell" owner:nil options:nil];
            
        if ([test count] >0)
        {
            for (id someObject in test)
            {
                if ([someObject isKindOfClass:[PSCustomCell class]])
                {
                    cell = someObject;
                    break;
                }
            }
        }
    }
    
    cell.lblDescricaoPerfil.text =  array[index];
    
    index++;
    
    return cell;
} 
 
@end
